/**
 * Created by Administrator on 2016/6/16.
 */


var page  = 1;
//自定义vue模板
var loading = false;
//分页
    $(document).ready(function(){
        $(window).scroll(function(){
            if (loading)
            {
                return;
            }
            if  ($(window).scrollTop() > $(document).height() - $(window).height() - 200)
            {
                loading = true;
                setTimeout(function(){
                    nextPage() ;
                }, 250);
            }
        });
    });


var docListMember = $("#docListMember");
//页面首次加载请求数据
$("document").ready(
    function(){
        //强制ajax同步
        var doctorList ='<section v-for="item in items" class="docListMember"><img v-if="item.nic_thumb != \'\'" v-bind:src="item.nic_thumb"><img v-if="item.nic_thumb ==\'\'" src="../images/userDefault.png"><section class="rightPart"><p><span>{{item.name}}</span><span>{{item.zhiwu}}</span></p><p><span>{{item.hospital_name}}</span><span>{{item.keshi}}</span></p><p><img src="../images/star.png"><span>{{item.score}}</span><span>接诊量: {{item.response_times}}</span></p><p>{{item.shan_chang_new}}</p><p class="id">{{item.d_id}}</p> </section> </section>';
        $("#docListMember").append(doctorList);
        $.ajaxSettings.async=false;
        $.post(commonval+"/doctorList",postArray,function(data){
            if(data.status == 1){
                $(".docListMember").css("display","block");
                var docListMember = new Vue({
                    el: '#docListMember',
                    data: {
                        items: data.data
                    }
                });

                $("section.docListMember").click(function(){
                    var url ="doctorInfo.html";
                    var id = $(this).children(".rightPart").children("p.id").text();
                    location.href = url+"?id="+id;
                    sessionStorage.d_id = id;
                    console.log(id);
                });
            }else{
                createWindow(data.msg);
            }
        })
})

//列表css交互
$("header p:nth-child(1)").on("tap",function(){
    $(".hidePlaylist").toggle();
});
$(".hidePlaylist ul li").on("tap",function(){
    $(".hidePlaylist ul li").removeClass("focus");
    $(this).addClass("focus");
    setTimeout(function(){
        $(".hidePlaylist").toggle();
        $(".hidePlaylist ul li").removeClass("active");
        $(".hidePlaylist ul li.focus").addClass("active").removeClass("focus");
    },500);
});

//列表请求排序
$(document).ready(function(){

    var type;
    $(".hidePlaylist ul li").on("tap",function(){
        var doctorList ='<section v-for="item in items" class="docListMember"><img v-if="item.nic_thumb != \'\'" v-bind:src="item.nic_thumb"><img v-if="item.nic_thumb ==\'\'" src="../images/userDefault.png"><section class="rightPart"><p><span>{{item.name}}</span><span>{{item.zhiwu}}</span></p><p><span>{{item.hospital_name}}</span><span>{{item.keshi}}</span></p><p><img src="../images/star.png"><span>{{item.score}}</span><span>接诊量: {{item.response_times}}</span></p><p>{{item.shan_chang_new}}</p><p class="id">{{item.d_id}}</p> </section> </section>';
        $("#docListMember").empty();
        $("#docListMember").append(doctorList);

        var index = $(this).index();
        switch(index){
            case 0:
                type = "zonghe";
                $("header p:nth-child(1)").text('默认');
                break;
            case 1:
                type = "score";
                $("header p:nth-child(1)").text('评分');
                break;
            case 2:
                type = "zixun";
                $("header p:nth-child(1)").text('接诊');
                break;
            case 3:
                type = "price_desc";
                $("header p:nth-child(1)").html('价格'+"<img src='../images/priceXia.png'>");
                break;
            case 4:
                type = "price_asc";
                $("header p:nth-child(1)").html('价格'+"<img src='../images/priceShang.png'>");
                break;
        }
        $.ajaxSettings.async=false;
        $.post(commonval+"/doctorList",{
            device:"wap",
            type:type
        },function(data){
            if(data.status == 1){
                $(".docListMember").css("display","block");
                var docListMember = new Vue({
                    el: '#docListMember',
                    data: {
                        items: data.data
                    }
                });
                $("section.docListMember").click(function(){
                    var url ="doctorInfo";
                    var id = $(this).children(".rightPart").children("p.id").text();
                    location.href = url+"?id="+id;
                    sessionStorage.d_id = id;
                });
            }else{
                createWindow(data.msg);
            }
        });
    });
});

$(document).ready(
    nextPage = function(){
     page++;
     $.ajaxSettings.async=false;
        postArray.page=page;
     $.post(commonval+"/doctorList",postArray,function(data){
         if(data.status == "1"&& data != null ){
             var doctorList ='<section v-for="item in items" class="docListMember"><img v-if="item.nic_thumb != \'\'" v-bind:src="item.nic_thumb"><img v-if="item.nic_thumb ==\'\'" src="../images/userDefault.png"><section class="rightPart"><p><span>{{item.name}}</span><span>{{item.zhiwu}}</span></p><p><span>{{item.hospital_name}}</span><span>{{item.keshi}}</span></p><p><img src="../images/star.png"><span>{{item.score}}</span><span>接诊量: {{item.response_times}}</span></p><p>{{item.shan_chang_new}}</p><p class="id">{{item.d_id}}</p> </section> </section>';
             $("#docListMember").append(doctorList);
             $(".docListMember").css("display","block");
             var docListMember = new Vue({
                 el: '#docListMember',
                 data: {
                     items: data.data
                 }
             });
             $("section.docListMember").click(function(){
                 var url ="doctorInfo.html";
                 var id = $(this).children(".rightPart").children("p.id").text();
                 location.href = url+"?id="+id;
                 sessionStorage.d_id = id;
                 console.log(id);
             });
         }else{
             page--;
         }
     });
  }
);





